Quick Start (Java)
Supported Environment
-
Minimum supported Android API level is
23
-
Target Android API level is
33
-
Camera permission
,Network permission
andNetwork connected environment
are required. -
Build target to REAL DEVICE
during the development process.
SeeSo SDK uses the front camera of the device.
Sample Project
Please check out sample project page for implementation and testing the SDK.
**Environment Set-ups **
-
Download SDK from Here. There should be two files:
- libgaze-release.aar
- gazetracker-release.aar
-
Make sure
Language
is set toJava
, andMinimum SDK
is set toAPI 23
. -
Copy
gazetracker-release.aar
andlibgaze-release.aar
to project'slibs
directory. -
Go to [File > Project Structure > Dependencies] from the Android Studio, then select
Jar Dependency
by selecting+
button. -
Type
libs/gazetracker-release.aar
inStep 1
, then selectimplementation
inStep 2
. PressOK
. -
Repeat
step 5
forlibs/libgaze-release.aar
. -
All added
aar
files should show up on theAll Dependencies
tab. -
Open [build.gradle] in
app
directory, the addimplementation files
for eachaar
file. -
Open
MainActivity
, and importcamp.visual.xxx
to check if all libraries are imported. -
Open [build.gradle] file and change
minSdkVersion
to23
,targetsdkVersion
to30
, then append the dependency for imported SDK modules.
Sample App Implemetation
Required Imports for Quick-Start
- Import all the dependcies to run sample codes in this Quick-Start.
- v2.x.x
- v3.x.x
// SeeSo Imports
import camp.visual.gazetracker.GazeTracker;
import camp.visual.gazetracker.callback.GazeCallback;
import camp.visual.gazetracker.callback.InitializationCallback;
import camp.visual.gazetracker.constant.InitializationErrorType;
import camp.visual.gazetracker.filter.OneEuroFilterManager;
import camp.visual.gazetracker.device.GazeDevice;
import camp.visual.gazetracker.gaze.GazeInfo;
// Android Imports
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;
// SeeSo Imports
import camp.visual.gazetracker.GazeTracker;
import camp.visual.gazetracker.callback.GazeCallback;
import camp.visual.gazetracker.callback.InitializationCallback;
import camp.visual.gazetracker.constant.InitializationErrorType;
import camp.visual.gazetracker.filter.OneEuroFilterManager;
import camp.visual.gazetracker.device.CameraPosition;
// Android Imports
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;
Check SDK Status
-
Try logging the SDK version to make sure SDK is ready to use.
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("SeeSo", "sdk version : " + GazeTracker.getVersionName());
}
} -
The internet and camera permission are need to be set at SDK manifest. The camera permission required at runtime, so you should get the camera permission before using teh SeeSo SDK.
Camera Permission
-
Following is a simple example getting the camera permission. The code will call
permissionGranted
when the permission is authorized.public class MainActivity extends AppCompatActivity {
private static final String[] PERMISSIONS = new String[]
{Manifest.permission.CAMERA};
private static final int REQ_PERMISSION = 1000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPermission();
Log.i("SeeSo", "sdk version : " + GazeTracker.getVersionName());
}
private void checkPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check permission status
if (!hasPermissions(PERMISSIONS)) {
requestPermissions(PERMISSIONS, REQ_PERMISSION);
} else {
checkPermission(true);
}
}else{
checkPermission(true);
}
}
@RequiresApi(Build.VERSION_CODES.M)
private boolean hasPermissions(String[] permissions) {
int result;
// Check permission status in string array
for (String perms : permissions) {
if (perms.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
if (!Settings.canDrawOverlays(this)) {
return false;
}
}
result = ContextCompat.checkSelfPermission(this, perms);
if (result == PackageManager.PERMISSION_DENIED) {
// When if unauthorized permission found
return false;
}
}
// When if all permission allowed
return true;
}
private void checkPermission(boolean isGranted) {
if (isGranted) {
permissionGranted();
} else {
finish();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQ_PERMISSION:
if (grantResults.length > 0) {
boolean cameraPermissionAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (cameraPermissionAccepted) {
checkPermission(true);
} else {
checkPermission(false);
}
}
break;
}
}
private void permissionGranted() {
}
}
GazeTracker Initialization
- This is an example that initializes
GazeTracker
. This example is implemented with the Galaxy Tab s5e screen origin. - Please enter proper
licenseKey
to initializeGazeTracker
.
- v2.x.x
- v3.x.x
...
GazeTracker gazeTracker = null;
...
private void permissionGranted() {
initGaze();
}
private void initGaze() {
GazeDevice gazeDevice = new GazeDevice();
gazeDevice.addDeviceInfo("SM-T720", -72f, -4f); // tab s5e
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";
GazeTracker.initGazeTracker(getApplicationContext(), gazeDevice, licenseKey, initializationCallback);
}
private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
}
private void initFail(InitializationErrorType error) {
String err = "";
if (error == InitializationErrorType.ERROR_INIT) {
// When initialization is failed
err = "Initialization failed";
} else if (error == InitializationErrorType.ERROR_CAMERA_PERMISSION) {
// When camera permission doesn not exists
err = "Required permission not granted";
}
...
else {
// Gaze library initialization failure
// It can ba caused by several reasons(i.e. Out of memory).
err = "init gaze library fail";
}
Log.w("SeeSo", "error description: " + err);
}
...
...
GazeTracker gazeTracker = null;
...
private void permissionGranted() {
initGaze();
}
private void initGaze() {
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";
GazeTracker.initGazeTracker(getApplicationContext(), licenseKey, initializationCallback);
}
private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
CameraPosition cp = new CameraPosition("SM-T720", -72f, -4f); // tab s5e
gazeTracker.addDevice(cp)
}
private void initFail(InitializationErrorType error) {
String err = "";
if (error == InitializationErrorType.ERROR_INIT) {
// When initialization is failed
err = "Initialization failed";
} else if (error == InitializationErrorType.ERROR_CAMERA_PERMISSION) {
// When camera permission doesn not exists
err = "Required permission not granted";
}
...
else {
// Gaze library initialization failure
// It can ba caused by several reasons(i.e. Out of memory).
err = "init gaze library fail";
}
Log.w("SeeSo", "error description: " + err);
}
...
GazeTracker Initialization with User Status Options
-
This is an example that initializes
GazeTracker
withUser Status
tracking code in SeeSo SDK. -
Only the given
User Status
options will be available for the initializedGazeTracker
. -
This will be available in all
development
environment, but not inproduction
environment. -
To use this in your
production
environment, please contact the SeeSo team.
- v2.x.x
- v3.x.x
private void initGaze() {
GazeDevice gazeDevice = new GazeDevice();
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";
UserStatusOption userStatusOption = new UserStatusOption();
if (isStatusAttention) {
userStatusOption.useAttention();
}
if (isStatusBlink) {
userStatusOption.useBlink();
}
if (isStatusDrowsiness) {
userStatusOption.useDrowsiness();
}
GazeTracker.initGazeTracker(getApplicationContext(), gazeDevice, licenseKey, initializationCallback, userStatusOption);
}
private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
...
private void initGaze() {
String licenseKey = "YOUR_DEVELOPMENT_LICENSE_KEY";
UserStatusOption userStatusOption = new UserStatusOption();
if (isStatusAttention) {
userStatusOption.useAttention();
}
if (isStatusBlink) {
userStatusOption.useBlink();
}
if (isStatusDrowsiness) {
userStatusOption.useDrowsiness();
}
GazeTracker.initGazeTracker(getApplicationContext(), licenseKey, initializationCallback, userStatusOption);
}
private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
...
InitializationCallback Implementation
-
This is an implementation example of
InitializationCallback
. The example returns theGazeTracker
when the process succeeds,null
when it fails. -
There are many
initialization error
, so please check error log if the initialization failed.private InitializationCallback initializationCallback = new InitializationCallback() {
@Override
public void onInitialized(GazeTracker gazeTracker, InitializationErrorType error) {
if (gazeTracker != null) {
initSuccess(gazeTracker);
} else {
initFail(error);
}
}
};
...
private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
}
Enroll Callbacks & Start Tracking
-
You can enroll callbacks that you want to call when
GazeTracker
is successfully initialized.GazeCallback
is the callback that relays gaze point data. -
Run
startTracking()
to startGaze Tracking
.private void initSuccess(GazeTracker gazeTracker) {
this.gazeTracker = gazeTracker;
this.gazeTracker.setGazeCallback(gazeCallback);
this.gazeTracker.startTracking();
}
private OneEuroFilterManager oneEuroFilterManager = new OneEuroFilterManager(2);
private GazeCallback gazeCallback = new GazeCallback() {
@Override
public void onGaze(GazeInfo gazeInfo) {
Log.i("SeeSo", "gaze coord " + gazeInfo.x + "x" + gazeInfo.y);
if (oneEuroFilterManager.filterValues(gazeInfo.timestamp, gazeInfo.x, gazeInfo.y)) {
float[] filteredValues = oneEuroFilterManager.getFilteredValues();
float filteredX = filteredValues[0];
float filteredY = filteredValues[1];
Log.i("SeeSo", "gaze filterd coord " + filteredX + "x" + filteredY);
}
}
};
Stop Tracking
-
stopTracking()
will stop theGazeTracker
, and the callback will stop passing gaze point data.private void stopTracking() {
GazeTracker.stopTracking();
}
GazeTracker destruction
-
This is an example of how to destroy the
GazeTracker
.private void releaseGaze() {
GazeTracker.deinitGazeTracker(this.gazeTracker);
this.gazeTracker = null;
}
Run
-
When the gaze tracking is started,
onGaze
callback will receive the gaze data from device and print logs. To obtain filtered gaze data, please use theOneEuroFilterManager
. -
When the
User Status
detector is activated,UserStatusCallback
callback will receive the activated status data from device. To get more details, please checkAndroid API
documentation.
TroubleShooting
-
In some cases, the unmatched NDK error like below can occur.
-
To resolve this problem, update the
classpath
ofbuild.gradle
independencies
. The updatingclasspath
4.1.x will resolve the error.